package Draw0512;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class DrawListenerV1_1 implements MouseListener , ActionListener {
    Graphics g ;
    JFrame jf;

    int x1,y1,x2,y2;//全局变量
    String type = "直线";//默认为画直线
    Color color = Color.BLACK;
    Shape[] shapeList = new Shape[100];
    int shapeSize = 0;

    @Override
    public void actionPerformed(ActionEvent e) {
        String ac = e.getActionCommand();
        if (ac.equals("")){
            JButton btn = (JButton) e.getSource();
            color = btn.getBackground();
        }else {
            type = ac;
        }
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        int x = e.getX();
        int y = e.getY();
    }

    @Override
    public void mousePressed(MouseEvent e) {
        int x = e.getX();
        int y = e.getY();
        x1 = x;
        y1 = y;
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        int x = e.getX();
        int y = e.getY();
        x2 = x;
        y2 = y;
        Shape s = new Shape();

            s.x1 = x1;
            s.x2 = x2;
            s.y1 = y1;
            s.y2 = y2;
            s.color = color;
            s.type = type;
            s.g = g;
            s.drawShape();
            System.out.println("当前图像完成，正在保存");

        shapeList[shapeSize] = s;
        shapeSize++;
    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}
